home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / FORTRAN Goodies / DynArray.txt < prev    next >
Encoding:
Text File  |  1992-11-03  |  776 b   |  33 lines  |  [TEXT/MPS ]

  1. c    Dynary.txt is an example of dynamically allocating 
  2. c    an array in FORTRAN:
  3.  
  4. c    Example provided for owners of Language Systems FORTRAN
  5. c    © 1992 Language Systems Corp.
  6. !!MP inlines.f
  7.  
  8.     program dynarray
  9.     
  10.     pointer /real*4/ myptr    !put the appropriate data type for the array in the //'s
  11.     integer*4 memneeded, numelems
  12.     
  13.     Write(*,*) 'How many elements in array?'
  14.     Read(*,*) numelems    !could also be calculated
  15.     memneeded = numelems*4    !number of elements times size of each element in bytes
  16.     myptr = NewPtr(memneeded)
  17.     if (myptr .ne. 0) then
  18.         call sub1(%val(myptr),numelems)    !%val is the "trick" that makes this work
  19.     end if
  20.     end
  21.     
  22.     
  23.     subroutine Sub1(a,i)    !This is just normal FORTRAN
  24.     Integer*4 i,j
  25.     Real*4 a(i)
  26.     
  27.     do j = 1,i
  28.         a(j) = j*1.532
  29.     end do
  30.     write(*,*) a
  31.     return
  32.     end
  33.